CFLAGS = -Wall -fpic -coverage -lm -std=c99

default: clean all playgame

rngs.o: rngs.h rngs.c
	gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
	gcc -c dominion.c -g  $(CFLAGS)

helper.o: helper.h helper.c dominion.o rngs.o
	gcc -c helper.c -g $(CFLAGS)
	
playdom: dominion.o playdom.c
	gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
	gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
	gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
	gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
	gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
	gcc -o player player.c -g dominion.o rngs.o interface.o $(CFLAGS)

unittest1: unittest1.c dominion.o rngs.o
	gcc -o unittest1 unittest1.c -g dominion.o rngs.o $(CFLAGS)

unittest2: unittest2.c dominion.o rngs.o
	gcc -o unittest2 unittest2.c -g dominion.o rngs.o $(CFLAGS)

unittest3: unittest3.c dominion.o rngs.o
	gcc -o unittest3 unittest3.c -g dominion.o rngs.o $(CFLAGS)

unittest4: unittest4.c dominion.o rngs.o
	gcc -o unittest4 unittest4.c -g dominion.o rngs.o $(CFLAGS)

cardtest1: cardtest1.c dominion.o rngs.o
	gcc -o cardtest1 cardtest1.c -g dominion.o rngs.o $(CFLAGS)

cardtest2: cardtest2.c dominion.o rngs.o
	gcc -o cardtest2 cardtest2.c -g dominion.o rngs.o $(CFLAGS)

cardtest3: cardtest3.c dominion.o rngs.o
	gcc -o cardtest3 cardtest3.c -g dominion.o rngs.o $(CFLAGS)

cardtest4: cardtest4.c dominion.o rngs.o
	gcc -o cardtest4 cardtest4.c -g dominion.o rngs.o $(CFLAGS)
	
randomtestcard: randomtestcard.c dominion.o rngs.o
	gcc -o randomtestcard randomtestcard.c -g dominion.o rngs.o $(CFLAGS)
	
randomtestadventurer: randomtestadventurer.c dominion.o rngs.o
	gcc -o randomtestadventurer randomtestadventurer.c -g dominion.o rngs.o $(CFLAGS)
	
testdominion: testdominion.c dominion.o rngs.o interface.o
	gcc -o testdominion testdominion.c -g dominion.o rngs.o interface.o $(CFLAGS)

unittestresults.out: clean all  
	gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)
	./unittest1 >> unittestresults.out
	gcov unittest1 >> unittestresults.out

	gcc -o unittest2 -g unittest2.c dominion.o rngs.o $(CFLAGS)
	./unittest2 >> unittestresults.out
	gcov unittest2 >> unittestresults.out

	gcc -o unittest3 -g unittest3.c dominion.o rngs.o $(CFLAGS)
	./unittest3 >> unittestresults.out
	gcov unittest3 >> unittestresults.out

	gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)
	./unittest4 >> unittestresults.out
	gcov unittest4 >> unittestresults.out

	gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o $(CFLAGS)
	./cardtest1 >> unittestresults.out
	gcov cardtest1 >> unittestresults.out

	gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o $(CFLAGS)
	./cardtest2 >> unittestresults.out
	gcov cardtest2 >> unittestresults.out

	gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)
	./cardtest3 >> unittestresults.out
	gcov cardtest3 >> unittestresults.out

	gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o $(CFLAGS)
	./cardtest4 >> unittestresults.out
	gcov cardtest4 >> unittestresults.out 
		
	gcov dominion  >> unittestresults.out 

randomtests.out: dominion.o rngs.o interface.o	
	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)
	./randomtestcard > randomtestcard.out
	gcov -b randomtestcard.c >> randomtestcard.out 
	gcov -b dominion.c  >> randomtestcard.out 
	
	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
	./randomtestadventurer > randomtestadventurer.out
	gcov -b randomtestadventurer.c >> randomtestadventurer.out 
	gcov -b dominion.c  >> randomtestadventurer.out 

playgame: dominion.o rngs.o interface.o
	gcc -o testdominion -g testdominion.c dominion.o rngs.o interface.o  $(CFLAGS)
	./testdominion > testdominion.out
	gcov -b testdominion.c >> testdominion.out 
	gcov -b dominion.c  >> testdominion.out 

dominionunit: DominionUnit.c dominion.o rngs.o helper.o
	gcc -o dominionunit -g  DominionUnit.c dominion.o rngs.o helper.o $(CFLAGS)
	
runtests: clean all
	cardtest1 > testresults.out
	cardtest2 > testresults.out
	cardtest3 > testresults.out
	cardtest4 > testresults.out
	unittest1 > testresults.out
	unittest2 > testresults.out
	unittest3 > testresults.out
	unittest4 > testresults.out
	randomtestcard > testresults.out
	randomtestadventurer > testresults.out
	testdominion >  testresults.out 
	gcov -b  testdominion >  testresults.out
	gcov -b cardtest1 > testresults.out
	gcov -b cardtest2 > testresults.out
	gcov -b cardtest3 > testresults.out
	gcov -b cardtest4 > testresults.out
	gcov -b unittest1 > testresults.out
	gcov -b unittest2 > testresults.out
	gcov -b unittest3 > testresults.out
	gcov -b unittest4 > testresults.out
	gcov -b randomtestcard > testresults.out
	gcov -b randomtestadventurer > testresults.out
	gcov -b dominion > testresults.out
	

testAll.out: dominion.o rngs.o interface.o
	gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)
	./unittest1 >> testAll.out
	gcov unittest1 >> testAll.out
	rm -f unittest1.c.gcov unittest1.gcda

	gcc -o unittest2 -g unittest2.c dominion.o rngs.o $(CFLAGS)
	./unittest2 >> testAll.out
	gcov unittest2 >> testAll.out
	rm -f unittest2.c.gcov unittest2.gcda

	gcc -o unittest3 -g unittest3.c dominion.o rngs.o $(CFLAGS)
	./unittest3 >> testAll.out
	gcov unittest3 >> testAll.out
	rm -f unittest3.c.gcov unittest3.gcda

	gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)
	./unittest4 >> testAll.out
	gcov unittest4 >> testAll.out
	rm -f unittest4.c.gcov unittest4.gcda

	gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o $(CFLAGS)
	./cardtest1 >> testAll.out
	gcov cardtest1 >> testAll.out
	rm -f cardtest1.c.gcov cardtest1.gcda

	gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o $(CFLAGS)
	./cardtest2 >> testAll.out
	gcov cardtest2 >> testAll.out
	rm -f cardtest2.c.gcov cardtest2.gcda

	gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)
	./cardtest3 >> testAll.out
	gcov cardtest3 >> testAll.out
	rm -f cardtest3.c.gcov cardtest3.gcda

	gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o $(CFLAGS)
	./cardtest4 >> testAll.out
	gcov cardtest4 >> testAll.out
	rm -f cardtest4.c.gcov cardtest4.gcda
	
	gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o $(CFLAGS)
	./randomtestcard >> testAll.out
	gcov randomtestcard >> testAll.out
	rm -f randomtestcard.c.gcov randomtestcard.gcda
	
	gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o $(CFLAGS)
	./randomtestadventurer >> testAll.out
	gcov randomtestadventurer >> testAll.out
	rm -f randomtestadventurer.c.gcov randomtestadventurer.gcda
	
	gcc -o testdominion -g testdominion.c dominion.o rngs.o interface.o $(CFLAGS)
	./testdominion >> testAll.out
	gcov testdominion >> testAll.out
	rm -f testdominion.c.gcov testdominion.gcda
	
	gcov -b dominion > testAll.out
	

all: playdom player testDrawCard testBuyCard badTestDrawCard unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard testdominion dominionunit

clean:
	rm playdom player testDrawCard testBuyCard badTestDrawCard unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard testdominion testdominion.out gameresults.out -f *.o *.exe *.gcov *.gcda *.gcno *.so *.out
